package com.example.demo.config;

import com.example.demo.utils.JavaUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

       String token = request.getHeader("user_token");
        System.out.println(token);
        System.out.println("请求正常进入");
        Claims claims= JavaUtils.parseJWT(token);
        System.out.println(claims);
        if(claims==null){
            return false;
        }
        return true;
    }
}
